<?php

namespace app\system\controller;

use app\common\model\ActionLogModel;
use think\Request;

class ActionLogController extends BaseController
{
    private $actionLog;
    /**
     * 初始化
     * AreaController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->actionLog = new ActionLogModel();
    }

    public function index(){
        $utype = $this->request->param('utype','system');
        $username = $this->request->param('username');
        $map['utype'] = $utype;
        $query ['utype'] = $utype;
        $query ['username'] = '';
        if(!empty($username)){
            $map['username'] = $username;
            $query ['username'] = $username;
        }
        $btime = $this->request->param('btime');
        if(!empty($btime)){
            $query['btime'] = $btime;
            $sbtime = strtotime($btime);
        }else{
            $sbtime = strtotime(0);
        }
        $etime = $this->request->param('etime');
        $query['etime'] = $etime;
        $setime = empty($etime)?time():strtotime($etime." 23:59:59");
        $map['create_time'] = ['between',[$sbtime,$setime]];
        $module = $this->request->param('module');
        if(!empty($module)){
            $map['module'] = $module;
            $query ['module'] = $module;
        }
        $controller = $this->request->param('controller');
        if(!empty($controller)){
            $map['controller'] = $controller;
            $query ['controller'] = $controller;
        }
        $action = $this->request->param('action');
        if(!empty($action)){
            $map['action'] = $action;
            $query ['action'] = $action;
        }
        $list = $this->actionLog->where($map)->order('id desc')->paginate(20,false,['query'=>$query]);
        $this->assign('list',$list);
        $this->assign('query',$query);
        return $this->fetch();
    }
}